package com.example.zhangxin.zyfypt_124zx.fragment;

import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

import com.example.zhangxin.zyfypt_124zx.R;
import com.example.zhangxin.zyfypt_124zx.activity.FocusActivity;
import com.example.zhangxin.zyfypt_124zx.activity.ViewMainActivity;

import static android.content.Context.MODE_PRIVATE;


/**
 * Created by Neusoft on 2017/4/9.
 */

public class Fragment5 extends Fragment {
    private  TextView tv1,tv2;
    private Button bt1,bt2,bt3;
    private View view=null;
    private Context context;
    private String username="",password="",sessionID="";//用户名密码
    private SharedPreferences sp;
    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        context=getActivity();
       //动态加载Fragment1的布局文件
        view=inflater.inflate(R.layout.fragment5,container,false);
        //获取布局上的控件，注意通过view获取
       // tvinfo=(TextView)view.findViewById(R.id.textView8);
        //tvinfo.setText("我的收藏");


        tv1=(TextView)view.findViewById(R.id.textView1) ;
        tv2=(TextView)view.findViewById(R.id.textView2) ;
        bt1=(Button)view.findViewById(R.id.button11) ;
        bt2=(Button)view.findViewById(R.id.button12) ;
        bt3=(Button)view.findViewById(R.id.button10) ;
        //tv1.setText("");
        //tv2.setText("");
        sp=context.getSharedPreferences("login",MODE_PRIVATE);
        readSP();

        tv2.setText(username);
        bt1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent=new Intent(getActivity(), ViewMainActivity.class);
                //Intent intent=new Intent(context, ViewMainActivity.class);
                startActivity(intent);
            }
        });
        bt2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent=new Intent(getActivity(), FocusActivity.class);
                //Intent intent=new Intent(context, ViewMainActivity.class);
                startActivity(intent);
            }
        });
        bt3.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                getActivity().onBackPressed();
            }
        });
        //注意Toast第一个参数上下文
        Toast.makeText(context, "加载Fragment我", Toast.LENGTH_SHORT).show();
        //返回动态生成的view
        return view;
    }

    private void readSP() {
        username = sp.getString("username", null);
    }


}
